---@class RedDotsGuildApplyHandler
RedDotsGuildApplyHandler = {};
local this = RedDotsGuildApplyHandler;
function RedDotsGuildApplyHandler.init()
    CloseEvent(Config.EventType.Union_Info_Change, this.update);
    CloseEvent(Config.EventType.Union_AllianceMerge_S2C, this.update);
    ListenEvent(Config.EventType.Union_Info_Change, this.update);
    ListenEvent(Config.EventType.Union_AllianceMerge_S2C, this.update);
    return this;
end

--
function RedDotsGuildApplyHandler.getFlag(...)
    if logicMgr.GuildManager.hasApplyGuildMembers() then
        return Config.RedDotsFlagState.Needful;
    end
    local type = ...;
    if type ~= nil and tonumber(type) == 1 and logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Guild) then
        local unionInfo = logicMgr.GuildManager.unionInfo;
        if unionInfo ~= nil and unionInfo.leader ~= nil then
            if tostring(unionInfo.leader.showInfo.playerId) == tostring(logicMgr.HeroManager.GetRoleInfo().playerId) then
                if logicMgr.GuildManager.applyAllyNum > 0 or logicMgr.GuildManager.hasAllyApply then
                    return Config.RedDotsFlagState.Needful;
                end
            end
        end
    end

    return Config.RedDotsFlagState.None;
end

function RedDotsGuildApplyHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.GuildApply);
end

return RedDotsGuildApplyHandler;